package pers.fjl.test.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import pers.fjl.common.po.Supply;
import pers.fjl.common.vo.SalesVo;
import pers.fjl.common.vo.SupplyVo;

import java.util.List;

@Repository
public interface SupplyDao extends BaseMapper<Supply> {
    /**
     * 查询所有的供应列表
     * @return list
     */
    @Select("SELECT c.cname, sl.supplier, s.number, s.date, s.supply_price " +
            "FROM commodity c, supplier sl, supply s " +
            "WHERE c.cid = s.cid AND s.supplier_id = sl.supplier_id ")
    List<SupplyVo> getAllSupply();

    /**
     * 根据供应商名称查找供应列表
     * @param queryString
     * @return list
     */
    @Select("SELECT c.cname, sl.supplier, s.number, s.date, s.supply_price " +
            "FROM commodity c, supplier sl, supply s " +
            "WHERE c.cid = s.cid AND s.supplier_id = sl.supplier_id AND sl.supplier LIKE '%${queryString}%' ")
    List<SupplyVo> searchBySupplier(String queryString);

    /**
     * 查询根据供应商名称得到的供应关系的数据条数
     * @param queryString
     * @return long
     */
    @Select("SELECT count(*) " +
            "FROM commodity c, supplier sl, supply s " +
            "WHERE c.cid = s.cid AND s.supplier_id = sl.supplier_id AND sl.supplier LIKE '%${queryString}%' ")
    long selectSearchCount(String queryString);
}
